package com.zyp.common.message.common.filter;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import javax.servlet.*;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Created by flying_bi on 2016/6/3.
 */

@Component
public class SwaggerFilter implements Filter {
    @Value("${run.mode}")
    private String runMode;

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {

    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        if(runMode.equalsIgnoreCase("develop")){
            filterChain.doFilter(servletRequest,servletResponse);
        }else{
            ((HttpServletResponse)servletResponse).setStatus(HttpServletResponse.SC_NOT_FOUND);//返回404状态码
        }
    }

    @Override
    public void destroy() {

    }
}
